<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/common/taglibs.jsp" %>
<div class="main-content">
    <div class="main-content-inner">
        <%@include file="/WEB-INF/common/back/breadcrumb.jsp" %>
        <div class="page-content">
            <form id="addForm" class="form-horizontal" role="form">
                <input type="hidden" name="id" value="${id}">
                <c:forEach items="${fieldMap['edit']}" var="field" varStatus="st">
                    <c:set var='fieldname' value="${field.name}" scope="page"/>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">
                                ${field.nickname}
                            <c:if test="${false eq field.nullable}"><span style="color: red;">*</span></c:if>
                        </label>
                        <div class="col-sm-9">
                            <c:choose>
                                <c:when test="${'text' eq field.type}">
                                    <input type="text" name="${field.name}" value="${obj[fieldname]}" class="col-xs-10 col-sm-5">
                                </c:when>
                                <c:when test="${'textarea' eq field.type}">
                                    <textarea class="col-xs-10 col-sm-5" name="${field.name}">${obj[fieldname]}</textarea>
                                </c:when>
                                <c:when test="${'dict' eq field.type}">
                                    <select qType="dict" name="${field.name}" class="col-xs-10 col-sm-5" data-options="<c:if test="${false eq field.nullable}">required:true</c:if>">
                                        <option value=""></option>
                                        <c:forEach items="${field.dictMap}" var="item">
                                            <option value="${item.key}" <c:if test="${item.key eq obj[fieldname]}">selected</c:if>>${item.value}</option>
                                        </c:forEach>
                                    </select>
                                </c:when>
                                <c:when test="${'date' eq field.type}">
                                    <c:choose>
                                        <c:when test="${'yyyy-MM-dd' eq field.format}">
                                            <input class="date-picker col-xs-10 col-sm-5" type="text" name="${field.name}" value="${obj[fieldname]}" onclick="WdatePicker()"/><i class="ace-icon fa fa-calendar fa-lg"></i>
                                        </c:when>
                                        <c:when test="${'yyyy-MM-dd HH:mm:ss' eq field.format}">
                                            <input class="date-picker col-xs-10 col-sm-5" type="text" name="${field.name}" value="${obj[fieldname]}" onclick="WdatePicker()"/><i class="ace-icon fa fa-calendar fa-lg"></i>
                                        </c:when>
                                    </c:choose>
                                </c:when>
                            </c:choose>
                        </div>
                    </div>
                </c:forEach>

                <div class="space-4"></div>

                <div class="clearfix form-actions">
                    <div class="col-md-offset-3 col-md-9">
                        <button class="btn btn-info" type="button" onclick="saveForm()">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                            保存
                        </button>
                        <button class="btn btn-grey" onclick="history.back()">
                            <i class="ace-icon fa fa-arrow-left bigger-110"></i>
                            返回
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    function saveForm() {
        $.ajax({
            type: "POST",
            url: "${contextPath}/auto/save",
            data: {o: 'Auto', params: JSON.stringify($("#addForm").serializeObject())},
            async: false,
            success: function (data) {
                if (data.success) {
                    window.location.href = "${contextPath}/auto/home?o=Auto";
                }
                else {
                    layer.msg(data.msg);
                }
            }
        });
    }
</script>
